<?php
    header("Content-Type:text/html;charset=utf-8");

    //链接数据库
    $conn;
    include '../public/conn.php';

    session_start();
    // 表单数据的获取
    // 标题
    $title = $_POST['logTitle'];
    // 内容
    $content = $_POST['logContent'];

    // 知识单元
    $order = $_POST['logUnit'];		
    // 权限
    $visible = $_POST['visible'];
    // 作者id
    $strName=$_SESSION['userName'];
    $id=mysql_query("select sid from student where sna='$strName'", $conn);
    $row=mysql_fetch_array($id);
    $sID=$row['sid'];
    $_SESSION['sid'] = $sID;
    //判断标题是否为空
    if($title==""){
    	echo("<script>");
		echo("alert('请输入标题！');");
		echo("window.location='student.php';");
		echo("</script>");
    }

    //判断日志内容是否为空
    if($content==""){
    	echo("<script>");
		echo("alert('请输入日志内容！');");
		echo("window.location='student.php';");
		echo("</script>");
    }

    // 对特殊字符处理
	$title = addslashes($title);
	$content = addslashes($content);

    //插入数据
//?
	$query = "INSERT INTO log (sid, unit_id, log_title, log_content, log_visible, log_date, log_time)
			VALUES ($sID, $order, '$title', '$content', $visible, NOW(), NOW())";				
	$result = mysql_query($query, $conn);

	//判断是否发表成功
	if($result){	
		echo("<script>");
		echo("alert('发表成功');");
		echo("window.location='student.php';");
		echo("</script>");		
	}
	
    else{
    	echo("<script>");		
		echo("alert('发表失败');");
		echo("window.location='student.php';");
		echo("</script>");
    }
?>